package com.ruoyi.sync;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
@Slf4j
/**
 * 异步接口
 * */
public class AsyncTask {
    @Async("taskExecutor")
    public void doTask1() {
        long t1 = System.currentTimeMillis();
        try {
            Thread.sleep(20000);
        } catch (Exception e) {
            e.printStackTrace();
        }

        long t2 = System.currentTimeMillis();
        log.info("task1 cost {} ms", t2 - t1);
    }

    @Async("taskExecutor")
    public void doTask2(){
        long t1 = System.currentTimeMillis();
        try {
            Thread.sleep(3000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        long t2 = System.currentTimeMillis();
        log.info("task2 cost {} ms", t2 - t1);
    }

}
